<?php
    /**
     * Created by PhpStorm.
     * User: mybook-lhp
     * Date: 18/6/5
     * Time: 下午3:18
     */

    namespace app\store\api;


    use app\common\controller\API;
    use app\store\model\CategoryModel;
    use app\store\model\StoreCategoryModel;

    class Category extends API
    {

        /**
         * 获取分类树
         * api GET  /store/category/layer
         *
         * @param string $field 字段名，例如使用逗号分隔：id,pid,name(可不传)
         *
         * @return array $data 树形结构
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         */
        public function layer()
        {

            $field = $this->request->param('field',"*");
            $this->result(CategoryModel::CategoryLayer($field));
        }

        /**
         * 获取分类列表
         * api GET  /store/category/lists
         *
         * @param string $field 字段名，例如使用逗号分隔：id,pid,name(可不传)
         * @param string $pid   分类ID(可不传)
         *
         * @return array $data 列表结构
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         */
        public function lists()
        {

            $field = $this->request->param('field',"*");
            $pid   = $this->request->param('pid',0);

            $data = CategoryModel::CategoryList($field,['pid' => $pid]);

            $this->result($data);
        }

        /**
         * 获取分类列表
         * api GET  /store/category/lists
         *
         * @param string $field 字段名，例如使用逗号分隔：id,pid,name(可不传)
         * @param string $pid   分类ID(可不传)
         *
         * @return array $data 列表结构
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         */
        public function listsTest()
        {

            $field = $this->request->param('field',"*");
            $pid   = $this->request->param('pid',0);
            $this->result(CategoryModel::CategoryList($field,['pid' => $pid]));
        }

    }